<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>老人管理-老人用药-新增老人用药</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="/senior_assets/layertw-assets/css/bootstrap.min.css" rel="stylesheet">
    <link href="/senior_assets/layertw-assets/css/style.css" rel="stylesheet">
    <link href="/senior_assets/layertw-assets/css/font-awesome.css" rel="stylesheet">
            <link rel="stylesheet" href="/plugins/SweetAlert/sweetalert.css" />
</head>
<body>
    <div class="container-fluid">
        <div class="om-ctl-mes">
            <div class="title">
                <div class="col-xs-12"><span class="fa fa-list-ul"> 老人管理</span><b class="fa fa-caret-right"></b><i><a href="../老人用药.html">老人用药</a></i><b class="fa fa-caret-right"></b><i>新增老人用药</i></div>
            </div>
            <div class="new-om-content col-xs-12">
                <div class="col-xs-6" id="adddiv">
               
                    <button type="button" id="addBtn">添加</button> 
                    <form class="myForm" action="/admin_eatmedicine/edit" method="post">
                    <?foreach($tMDatas as $tMRow){?>
                    <div class="med-add">
                        <div class="col-xs-12">
                            <div class="col-xs-8">
                                <label>药品名</label>
                            <select name="medicine_name" style="width:2.40rem">
                                <option value="0">请选择</option>
                            <?foreach($tMLDatas as $tMLRow){?>
                                <option value="<?=$tMLRow['id']?>" <?if($tMLRow['id'] == $tMRow['ml_id']){echo 'selected';}?>><?=$tMLRow['name']?></option>
                                <?}?>
                            </select>
                                <label>数量</label>
                                <input type="number" style="width:50px;" name="num" value="<?=$tMRow['num']?>"/>
                                <label style="width:.50rem">单位</label>
                                <select name="unit">
                                <option value="0">请选择</option>
                                <option value="1" <?if($tMRow['unit'] == 1){echo 'selected';}?>>片</option>
                                <option value="2" <?if($tMRow['unit'] == 2){echo 'selected';}?>>支</option>
                                <option value="3" <?if($tMRow['unit'] == 3){echo 'selected';}?>>盒</option>
                                <option value="4" <?if($tMRow['unit'] == 4){echo 'selected';}?>>粒</option>
                                <option value="5" <?if($tMRow['unit'] == 5){echo 'selected';}?>>甁</option>
                            </select>
                                <label>用药时间</label>
                                <select name="at" style="width:1.20rem">
<option value="0">请选择</option>
<option value="1" <?if($tMRow['at'] == 1){echo 'selected';}?>>早上</option>
<option value="2" <?if($tMRow['at'] == 2){echo 'selected';}?>>上午</option>
<option value="3" <?if($tMRow['at'] == 3){echo 'selected';}?>>中午</option>
<option value="4" <?if($tMRow['at'] == 4){echo 'selected';}?>>下午</option>
<option value="5" <?if($tMRow['at'] == 5){echo 'selected';}?>>晚上</option>
<option value="6" <?if($tMRow['at'] == 6){echo 'selected';}?>>其他</option>
<option value="7" <?if($tMRow['at'] == 7){echo 'selected';}?>>临睡用药</option>
                            </select><input type="radio" name="fanqian<?=$tMLRow['id']?>" value="1" <?if($tMRow['fanqian'] == 1){echo 'checked';}?>> 饭前</select>
                                 <input type="radio" name="fanqian<?=$tMLRow['id']?>" value="2" <?if($tMRow['fanqian'] == 2){echo 'checked';}?>> 饭后</select>
                            </div>
                            <div class="col-xs-4"><p><img src="/senior_assets/layertw-assets/img/02_03.png"></p>
                            </div>
                        </div>
                        <div class="add-say"><label>医嘱 </label><input type="text" name="remarks" value="<?=$tMRow['remarks']?>"></div>
                    </div>
                    <?}?> 
                    </form>           
                </div>
                <form action="post" name="eatme">
                <div class="col-xs-6" id="editdiv">       
                    <button type="button" id="save">保存</button>
                    <button type="button"  onclick="window.location.href='/admin_eatmedicine'">取消</button>
                    <input type="hidden" name="sid" value="<?=$pSid?>">

                </div>
                </form>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="/layertwo-assets/js/jquery.min.js"></script>
    <script type="text/javascript" src="/plugins/datepicker/WdatePicker.js" charset="UTF-8"></script>
    <script src="/plugins/bootstrap/js/bootstrap.min.js"></script>
    <script src="/plugins/SweetAlert/sweetalert.min.js"></script><!--alert插件-->
    <script src="/js/jquery.form.js"></script><!--form表单插件-->
</body>
</html>
<script>
var k = 0;
$('#addBtn').on('click',function(){
    $('#editdiv').append('<div class="med-edit" id="a'+k+'"><img src="/senior_assets/layertw-assets/img/del_03.png" class="delbtn" onclick="delbtn($(this).parent().remove())"><div class="col-xs-12"><div class="col-xs-8"><label>药品名</label><select name="medicine_name[]" style="width:2.40rem"><option value="0">请选择</option><?foreach($tMLDatas as $tMLRow){?><option value="<?=$tMLRow['id']?>"><?=$tMLRow['name']?></option><?}?></select><label>数量</label><input type="number" style="width:50px;" name="num[]" value=""/><label style="width:.50rem">单位</label><select name="unit[]"><option value="0">请选择</option><option value="1">片</option><option value="2" >支</option><option value="3">盒</option><option value="4">粒</option><option value="5">甁</option></select><br><label>用药时间</label><select name="at[]" style="width:1.20rem"><option value="0">请选择</option><option value="1" >早上</option><option value="2">上午</option><option value="3">中午</option><option value="4">下午</option><option value="5">晚上</option><option value="6" >其他</option><option value="7">临睡用药</option></select><input type="radio" name="fanqian'+k+'" value="1"> 饭前</select><input type="radio" name="fanqian'+k+'" value="2"> 饭后</select></div><div class="col-xs-4"><p><img src="/senior_assets/layertw-assets/img/02_03.png"></p></div></div><div class="add-say"><label>医嘱 </label><input type="text" name="remarks[]" value=""></div></div>');
    k++;
})
$('#save').click(function(){
    // $('#enddatetime').removeAttr('disabled');
    var data = $('form[name="eatme"]').serialize();
    // alert(data);
    $.post('/admin_eatmedicine/add',data,function(obj){
        cg_alert_add(obj,'/admin_eatmedicine/','/admin_eatmedicine/add');
        // $('#enddatetime').attr('disabled',true);
    });
});
function delbtn(){}
function cg_alert_add(obj,list_url,add_url){
    if(obj.status == 1){
        swal({
            title: obj.msg,
            confirmButtonText:'继续添加',
            confirmButtonColor: "#DD6B55",
            showCancelButton: true,
            cancelButtonText:'返回列表',
            type: "success",
        },function(isConfirm){
            if (isConfirm) {
                location.href = add_url;
            }else{
                location.href = list_url;
            }
        });
    }else{
        swal(obj.msg,'','error');
    }

}
function cg_alert_edit(obj,list_url,edit_url){
    if(obj.status == 1){
        swal({
            title: obj.msg,
            confirmButtonText:'继续修改',
            confirmButtonColor: "#DD6B55",
            showCancelButton: true,
            cancelButtonText:'返回列表',
            type: "success",
        },function(isConfirm){
            if (isConfirm) {
                location.href = edit_url;
            }else{
                location.href = list_url;
            }
        });
    }else{
        swal(obj.msg,'','error');
    }

}
function cg_confirm_del(del_url,jump_url){
    swal({
            title: '您确定要删除吗？',
            text:'删除之后不能恢复',
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText:'确定',
            closeOnConfirm: false,
            cancelButtonText:'取消'
        },
        function(isConfirm){
            if(isConfirm){
                window.obj = '';
                $.ajax({
                    url: del_url,
                    dataType: "json",
                    async:false,
                    success: function (obj) {
                        window.obj = obj;
                    }
                });

                if(window.obj.status == 1){
                    swal({title:"删除成功!", type:"success"},function(){
                        location.href = jump_url;
                    });
                }else{
                    swal({title:window.obj.msg, type:"error"});
                }
            }
        });
}
</script>